package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.models.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
public class NursingLevelContorller {
    @Autowired
    private NursingLevelService nursingLevelService;
    //查询所有
    @GetMapping("/listAll")
    public ResponseResult listAll() {
        List<NursingLevelVo> nursingLevelVos = nursingLevelService.findAll();
        return  ResponseResult.success(nursingLevelVos);
    }
    //新增
    @PostMapping("/insert")
    public ResponseResult insert(NursingLevelDto nursingLevelDto) {
        nursingLevelService.add(nursingLevelDto);
        return ResponseResult.success();
    }
    //条件分页查询 护理等级名称name，护理等级状态status，分页pageNum，分页pageSize
    @GetMapping("/listByPage")
    public ResponseResult Page(
            String name,
            Integer pageNum,
            Integer pageSize,
            Integer status
    ) {
        PageResponse<NursingLevelVo> nursingLevelVos = nursingLevelService.page(name, pageNum, pageSize, status);
        return ResponseResult.success(nursingLevelVos);
    }
    //根据id查询
    @GetMapping("/{id}")
    public ResponseResult findById(@PathVariable Long id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.findById(id);
        return ResponseResult.success(nursingLevelVo);
    }
    //修改
    @PutMapping("/update")
    public ResponseResult update(NursingLevelDto nursingLevelDto) {
        nursingLevelService.update(nursingLevelDto);
        return ResponseResult.success();
    }
    //删除
    @DeleteMapping("/delete/{id}")
    public ResponseResult deleteById(@PathVariable Long id){
        nursingLevelService.deleteById(id);
        return ResponseResult.success();
    }
    //启动/禁用
    @PutMapping("/status/{id}/{status}")
    public ResponseResult status( @PathVariable Long id, @PathVariable Integer status) {
        nursingLevelService.status(id, status);
        return ResponseResult.success();
    }
}
